package com.ruoyi.project.system.address.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.address.domain.FlowAddress;
import com.ruoyi.project.system.address.service.IFlowAddressService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 推流Controller
 * 
 * @author ruoyi
 * @date 2024-11-11
 */
@Controller
@RequestMapping("/system/address")
public class FlowAddressController extends BaseController
{
    private String prefix = "system/address";

    @Autowired
    private IFlowAddressService flowAddressService;

    @RequiresPermissions("system:address:view")
    @GetMapping()
    public String address()
    {
        return prefix + "/address";
    }

    /**
     * 查询推流列表
     */
    @RequiresPermissions("system:address:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FlowAddress flowAddress)
    {
        startPage();
        List<FlowAddress> list = flowAddressService.selectFlowAddressList(flowAddress);
        return getDataTable(list);
    }

    /**
     * 导出推流列表
     */
    @RequiresPermissions("system:address:export")
    @Log(title = "推流", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FlowAddress flowAddress)
    {
        List<FlowAddress> list = flowAddressService.selectFlowAddressList(flowAddress);
        ExcelUtil<FlowAddress> util = new ExcelUtil<FlowAddress>(FlowAddress.class);
        return util.exportExcel(list, "推流数据");
    }

    /**
     * 新增推流
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存推流
     */
    @RequiresPermissions("system:address:add")
    @Log(title = "推流", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FlowAddress flowAddress)
    {
        return toAjax(flowAddressService.insertFlowAddress(flowAddress));
    }

    /**
     * 修改推流
     */
    @RequiresPermissions("system:address:edit")
    @GetMapping("/edit/{flowId}")
    public String edit(@PathVariable("flowId") Long flowId, ModelMap mmap)
    {
        FlowAddress flowAddress = flowAddressService.selectFlowAddressByFlowId(flowId);
        mmap.put("flowAddress", flowAddress);
        return prefix + "/edit";
    }

    /**
     * 修改保存推流
     */
    @RequiresPermissions("system:address:edit")
    @Log(title = "推流", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FlowAddress flowAddress)
    {
        return toAjax(flowAddressService.updateFlowAddress(flowAddress));
    }

    /**
     * 删除推流
     */
    @RequiresPermissions("system:address:remove")
    @Log(title = "推流", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(flowAddressService.deleteFlowAddressByFlowIds(ids));
    }
}
